package com.rybbaby.tss.front.tssMealFee.dao.imp;

import com.rybbaby.tss.core.web.dao.imp.GenericDao;
import com.rybbaby.tss.front.tssMealFee.dao.ITssMealFeeDao;
import com.rybbaby.tss.front.tssMealFee.entity.TssMealFee;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

/**
 * @description 订金表数据库操作实现
 * 
 * @author 雷春琼
 * 
 * @createDate 2017-08-09 下午11:56:55
 */
@Repository
public class TssMealFeeDaoImp extends GenericDao<TssMealFee> implements ITssMealFeeDao {

    @Override
    public TssMealFee findByStuId(String stuId) throws Exception {
        TssMealFee TssMealFee = this.findUniqueByProperty(TssMealFee.class, "stuId", stuId);
        return TssMealFee;
    }

    @Override
    public int deductionDayMealFee(TssMealFee tssMealFee) {
        //String sql = "update tss_meal_fee SET amount="+tssMealFee.getAmount()+",consumptionAmount="+tssMealFee.getConsumptionAmount()+" where id ='"+tssMealFee.getId()+"'";
        String sql = "update tss_meal_fee SET consumptionAmount=consumptionAmount+dayMealFee,surplusAmout=surplusAmout-dayMealFee where id ='"+tssMealFee.getId()+"'";
        return this.updateBySql(sql);
    }

    @Override
    public int plusDayMealFee(TssMealFee tssMealFee) {
        //String sql = "update tss_meal_fee SET amount="+tssMealFee.getAmount()+",consumptionAmount="+tssMealFee.getConsumptionAmount()+" where id ='"+tssMealFee.getId()+"'";
        String sql = "update tss_meal_fee SET consumptionAmount=consumptionAmount-dayMealFee ,surplusAmout=surplusAmout+dayMealFeewhere id ='"+tssMealFee.getId()+"'";
        return this.updateBySql(sql);
    }

    @Override
    public boolean batchDeductionDayMealFee(ArrayList<Object[]> params) {
        String sql = "update tss_meal_fee SET consumptionAmount=consumptionAmount+dayMealFee,surplusAmout=surplusAmout-dayMealFee where stuId = ?";
        return this.batchUpdate(sql,params);
    }
}
